<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Set应用</title>
</head>
<body>
    <script>
        // 数组去重
        // let arr1 = [1,2,3,2,1,5,4];
        // let s1 = new Set(arr1);
        // console.log(s1);
        // let newArr = [...s1];
        // console.log(newArr);

        // console.log('Array.from',Array.from(s1));
        //[...new Set([arr1])]
        
        // 数组转成 Set   new Set(数组)
        // Set 转成数组   [...Set]   Array.from(Set)

        // 取交集
        // let arr1 = [1,2,3,4];
        // let arr2 = [3,4,5,6];
        // let result = arr1.filter((item)=>{
        //     let s = new Set(arr2);
        //     return s.has(item);
        // })
        // console.log(result);

        // 取并集 
        // let arr1 = [1,2,3,2,4];
        // let arr2 = [3,4,5,6,3,2];
        // let arr3 = [...new Set([...new Set(arr1),...new Set(arr2)])];
        // let arr4 = [...new Set([...arr1,...arr2])];
        // console.log(arr3,arr4);

        // 取差集

        let arr1 = [1,2,3,2,4];
        let arr2 = [3,4,5,6,3,2];

        let arr3 = arr1.filter(item=>{
            let s = new Set(arr2);
            return !s.has(item);
        })
        console.log(arr3);

    </script>
</body>
</html>